package org.itworks.biodev.gui.panels;

import java.awt.event.ActionEvent;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Observable;

import javax.swing.JOptionPane;

import org.itworks.biodev.model.*;
import org.itworks.helpers.mvc.*;

import com.toedter.calendar.JDateChooser;

public class SalariesPanelControler extends AbstractControler {
	private SalariesPanelModel model;
	
	public SalariesPanelControler(SalariesPanelModel model) {
		this.model = model;
	}

	@Override
	public void viewLoaded() {
		// TODO Auto-generated method stub
		
	}

	public void filterSalariesButtonActionPerformed(ActionEvent actionEvent,JDateChooser fromSalariesDateChooser,JDateChooser toSalariesDateChooser) throws Exception {
		// TODO Auto-generated method stub
		
		if(fromSalariesDateChooser.getDate()!=null && toSalariesDateChooser.getDate() != null)
		{
			if (fromSalariesDateChooser.getDate().before(toSalariesDateChooser.getDate())) {
				this.model.setSalaryList(SalariesTable.getInstance().findSalaryForPeriod(fromSalariesDateChooser.getDate(),toSalariesDateChooser.getDate()));
			}
			else
			{
				JOptionPane.showMessageDialog(null,"La date de debut doit etre anterieure a celle de la fin","Erreur",JOptionPane.ERROR_MESSAGE);
			}
		}	
	}

	public Observable getModel() {
		return this.model;
	}
}
